package com.angel.architecture.daos.impl;

import java.util.Collection;

import org.hibernate.criterion.Restrictions;

import com.angel.architecture.daos.UserRoleDAO;
import com.angel.architecture.persistence.beans.Role;
import com.angel.architecture.persistence.beans.User;
import com.angel.architecture.persistence.beans.UserRoles;
import com.angel.architecture.persistence.ids.ObjectId;
import com.angel.dao.generic.impl.GenericSpringHibernateDAO;


public class UserRoleSpringHibernateDAO extends GenericSpringHibernateDAO<UserRoles, ObjectId> implements UserRoleDAO {

    public UserRoleSpringHibernateDAO(){
        super(UserRoles.class, ObjectId.class);
    }
    public UserRoles findUniqueByUserAndRole(User user, Role role) {
    	//TODO Do findUniqueByUserAndRole for UserRoleDAO.
        //return super.findUniqueByCriteria(Restrictions.eq("user", user), Restrictions.eq("rol", role));
        return null;
    }

    public Collection<UserRoles> findAllByRole(Role role) {
        return this.findAllByCriteria(Restrictions.eq("rol", role));
    }

    public Collection<UserRoles> findAllByUser(User user) {
        return this.findAllByCriteria(Restrictions.eq("user", user));
    }

    public void deleteUserRoles(UserRoles userRoles) {
        super.delete(userRoles);
    }

    public boolean exist(User user, Role role) {
        return this.findUniqueByUserAndRole(user, role) != null;
    }
}
